package org.javaforever.gatescore.verb;

import java.util.ArrayList;
import java.util.List;

import org.javaforever.gatescore.core.FrontCodeBlock;
import org.javaforever.gatescore.core.FrontDomain;
import org.javaforever.gatescore.core.FrontMethod;
import org.javaforever.gatescore.core.FrontVerb;
import org.javaforever.gatescore.core.Statement;
import org.javaforever.gatescore.core.Writeable;
import org.javaforever.gatescore.core.WriteableUtil;
import org.javaforever.gatescore.exception.ValidateException;
import org.javaforever.gatescore.utils.StringUtil;

public class FilterExcel extends FrontVerb{
	private static final long serialVersionUID = 1007425592831193320L;

	public FilterExcel(FrontDomain d) throws ValidateException{
		super(d);	
		this.denied = domain.isVerbDenied("FilterExcel");
		this.setVerbName("Filter"+d.getCapFirstPlural() + "Excel");
	}
	
	@Override
	public FrontMethod generateControllerMethod()  throws Exception {
		if (this.denied)
			return null;
		else {
			FrontMethod method = new FrontMethod();
			method.setStandardName("filter"+this.domain.getCapFirstPlural()+ "Excel");
			List<Writeable> sList = new ArrayList<Writeable>();
			sList.add(new Statement(1000L, 2, "filter"+this.domain.getCapFirstPlural() + "Excel() {"));
			sList.add(new Statement(2000L, 3,"var params0 = this.buildParams(this.listQuery, this.postForm)"));
			sList.add(new Statement(3000L, 3,"var query = this.toQueryString(params0)"));
			sList.add(new Statement(4000L, 3,"window.location.href = this.baseApi + '"+this.domain.getLowerFirstDomainName()+this.domain.getControllerNamingSuffix()+"/filter"+this.domain.getCapFirstPlural()+"Excel?' + query"));
			sList.add(new Statement(5000L, 2, "},"));
			method.setMethodStatementList(WriteableUtil.merge(sList));
			return method;
		}
	}

	@Override
	public FrontMethod generateApiMethod()  throws Exception {
		return null;
	}

	@Override
	public FrontCodeBlock generateRouteBlockBlock() throws Exception {
		return null;
	}

	@Override
	public FrontMethod generateControllerMethod(String indexSuffix) throws Exception {
		if (this.denied)
			return null;
		else {
			FrontMethod method = new FrontMethod();
			method.setStandardName("filter"+this.domain.getCapFirstPlural()+ "Excel");
			List<Writeable> sList = new ArrayList<Writeable>();
			sList.add(new Statement(1000L, 2, "filter"+this.domain.getCapFirstPlural() + "Excel() {"));
			sList.add(new Statement(2000L,3,"var params0 = this.buildParams"+indexSuffix+"(this.listQuery"+indexSuffix+", this.postForm"+indexSuffix+")"));
			sList.add(new Statement(3000L,3,"var query = this.toQueryString(params0)"));
			sList.add(new Statement(4000L,3,"window.location.href = this.baseApi + '"+this.domain.getLowerFirstDomainName()+this.domain.getControllerNamingSuffix()+"/filter"+this.domain.getCapFirstPlural()+"Excel?' + query"));
			sList.add(new Statement(5000L, 2, "},"));
			method.setMethodStatementList(WriteableUtil.merge(sList));
			return method;
		}
	}

}
